﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text;
using AvaloniaApplication1.Core;

namespace AvaloniaApplication1.Validations
{
    public class TestValidation : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            try
            {
                int port = Convert.ToInt32(value);
                if (port <= 0 || port >= 65535)
                {
                    return new ValidationResult("端口号必须介于0-65535之间");
                }
                return ValidationResult.Success;
            }
            catch (Exception ex)
            {
                return new ValidationResult("端口号必须为数字");
            }
        }
    }
}
